The Goal 🎯
- The Task: Find the best route from a source server `S` to all other servers.
-
The Output: For every server `i`, you must compute:
- Total Latency: The minimum cost (shortest path) from `S` to `i`.
- Next Hop: The *first server* on that shortest path.
- Example: If the best path from `S` to `D` is `S -> A -> B -> D`, the **Next Hop** is `A`.
The Network 💾
We will use an Adjacency List to store the network.
- Servers are nodes.
- Connections are bi-directional edges.
- Latency is a positive weight.
// Links: 0-1 (10ms), 0-2 (3ms)
adj = [
0: [(1, 10), (2, 3)],
1: [(0, 10)],
2: [(0, 3)],
...
]
adj = [
0: [(1, 10), (2, 3)],
1: [(0, 10)],
2: [(0, 3)],
...
]
The Output Format ⚙️
You must print `V` lines. Each line `i` corresponds to server `i`.
[latency] [next_hop]For a reachable node.
0 -1If the node is the source `S` itself.
-1 -1If the node is unreachable from `S`.